//
//  ST_BaseRefreshController.m
//  ST_BaseMall
//
//  Created by 昱胜 on 2022/9/2.
//

#import "ST_BaseRefreshController.h"

static NSString *FDMSG_Home_DataRefresh                      = @"数据加载中...";
static NSString *FDMSG_Home_DataEmpty                        = @"数据空空如也...";
static NSString *FDNoNetworkMsg                              = @"无网络连接,请检查网络设置";

@interface ST_BaseRefreshController ()<ST_RefreshDataSource>
@property (nonatomic, strong) NSMutableArray *images;
@property (nonatomic, strong) NSMutableArray *refreshImages;

@end

@implementation ST_BaseRefreshController

- (void)dealloc {
    NSLog(@"%s", __FUNCTION__);
    NSLog(@"%@", self.class);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSource = self;
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor appWhiteLabelColor];
    self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;
    self.fd_interactivePopDisabled = NO;
    self.fd_prefersNavigationBarHidden = NO;
}
#pragma mark ATRefreshDataSource
- (NSArray <UIImage *>*)refreshFooterData{
    return self.refreshImages;
}
- (NSArray <UIImage *>*)refreshHeaderData{
    return self.refreshImages;
}
- (NSArray <UIImage *>*)refreshLoaderData{
    return self.images;
}
- (UIImage *)refreshEmptyData{
    return [UIImage imageNamed:@"icon_data_empty"];
}
- (UIImage *)refreshErrorData{
    return [UIImage imageNamed:@"icon_net_error"];
}
- (NSString *)refreshLoaderToast{
    return FDMSG_Home_DataRefresh;
}
- (NSString *)refreshErrorToast{
    return FDNoNetworkMsg;
}
- (NSString *)refreshEmptyToast{
    return FDMSG_Home_DataEmpty;
}
- (NSMutableArray *)images{
    if (!_images) {
        _images = @[].mutableCopy;
        for (int i = 1; i <= 8; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"load%@", @(i)]];
            if (!image) {
                break;
            }
            [_images addObject:image];
        }
    }
    return _images;
}

- (NSMutableArray *)refreshImages{
    if (!_refreshImages) {
        _refreshImages = @[].mutableCopy;
        for (int i = 1; i <= 4; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading%@", @(i+1)]];
            if (!image) {
                break;
            }
            [_refreshImages addObject:image];
        }
        for (int i = 4; i > 0; i--) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading%@", @(i+1)]];
            if (!image) {
                break;
            }
            [_refreshImages addObject:image];
        }
    }
    return _refreshImages;
}


@end
